﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SWCInvoice.Enums;
using SWCInvoice.Model;

namespace SWCInvoice.Returntyps {
    public abstract class BaseInfo {       

        #region Fields
        
        /// <summary>
        /// The exception list
        /// </summary>
        private List<Exception> _exceptionList;

        /// <summary>
        /// Message typ of the message
        /// </summary>
        private MessageTyp _messageTyp;

        #endregion

        #region Properties

        #region Abstract

        /// <summary>
        /// Base object resource typ
        /// </summary>        
        public abstract string ResourceString {
            get;
        }

        #endregion

        protected string ResourceNoneMessageTitleString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "NoneMessageTitle"), Properties.ResourceTextMessages.Culture); }
        }

        protected string ResourceNoneMessageDescriptionString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "NoneMessageDescription"), Properties.ResourceTextMessages.Culture); }
        }

        protected string ResourceInformationMessageTitleString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "InformationMessageTitle"), Properties.ResourceTextMessages.Culture); }
        }

        protected string ResourceInformationMessageDescriptionString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "InformationMessageDescription"), Properties.ResourceTextMessages.Culture); }
        }

        protected string ResourceWarningMessageTitleString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "WarningMessageTitle"), Properties.ResourceTextMessages.Culture); }
        }

        protected string ResourceWarningMessageDescriptionString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "WarningMessageDescription"), Properties.ResourceTextMessages.Culture); }
        }

        protected string ResourceErrorMessageTitleString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "ErrorMessageTitle"), Properties.ResourceTextMessages.Culture); }
        }

        protected string ResourceErrorMessageDescriptionString {
            get { return Properties.ResourceTextMessages.ResourceManager.GetString(string.Concat(ResourceString, "ErrorMessageDescription"), Properties.ResourceTextMessages.Culture); }
        }

        /// <summary>
        /// The exception list
        /// </summary>        
        public List<Exception> ExceptionList {
            get {
                if (_exceptionList == null)
                    _exceptionList = new List<Exception>();
                return _exceptionList; }
        }

        /// <summary>
        /// Message typ of the message
        /// </summary>        
        public MessageTyp MessageTyp {
            get { return _messageTyp; }
            set { _messageTyp = value; }
        }

        #endregion

        #region Methods

        #region Abstracts

        /// <summary>
        /// Derive the message typ by object states and set ist to the object        
        /// </summary>
        /// <returns>The message typ</returns>
        public abstract MessageTyp SetMessageTypByObjectContent();

        /// <summary>
        /// Enrich the messagetexts with parameters
        /// </summary>
        /// <param name="message">The message object</param>
        /// <returns>The enriched message object</returns>
        public abstract Message EnrichMessageWithParameters(Message message);

        #endregion

        /// <summary>
        /// Base method to set the message typ by the object content
        /// </summary>
        /// <returns>The message tye</returns>
        protected MessageTyp SetMessageTypByObjectContentBase() {
            if (MessageTyp != MessageTyp.None)
                return MessageTyp;
            else
                if (ExceptionList != null && ExceptionList.Count > 0) {
                    MessageTyp = MessageTyp.Error;
                    return MessageTyp;
                }

            if(MessageTyp == MessageTyp.None)
                MessageTyp = SetMessageTypByObjectContent();

            return MessageTyp;        
        }

        /// <summary>
        /// Create a message witch can be drop to the messagebox/log
        /// </summary>
        /// <returns></returns>
        public Message GetMessage() {
            Message message = null;

            //Set the Message typ to the object
            SetMessageTypByObjectContentBase();

            message = new Message(GetMessageTitle(), MessageTyp, GetMessageDescription());
            message = EnrichMessageWithParameters(message);

            return message;
        }
        
        /// <summary>
        /// Get the message description by the message result typ
        /// </summary>
        /// <returns>message description</returns>
        protected string GetMessageDescription() {

            switch (MessageTyp) {
                case MessageTyp.None:
                    return ResourceNoneMessageDescriptionString;
                    break;
                case MessageTyp.Information:
                    return ResourceInformationMessageDescriptionString;
                    break;
                case MessageTyp.Warning:
                    return ResourceWarningMessageDescriptionString;
                    break;
                case MessageTyp.Error:
                    return ResourceErrorMessageDescriptionString;
                    break;
                default:
                    return "";
                    break;
            }
        
        }

        /// <summary>
        /// Get the message description by the message result typ
        /// </summary>
        /// <returns>message title</returns>
        protected string GetMessageTitle() {
            switch (MessageTyp) {

                case MessageTyp.None:
                    return ResourceNoneMessageTitleString;
                    break;
                case MessageTyp.Information:
                    return ResourceInformationMessageTitleString;
                    break;
                case MessageTyp.Warning:
                    return ResourceWarningMessageTitleString;
                    break;
                case MessageTyp.Error:
                    return ResourceErrorMessageTitleString;
                    break;
                default:
                    return "";
                    break;
            }
        }
        
        #endregion
    }
}
